Firearms: code used to generate predictions in R

R code:  note the following commands were run in interactive format.  This is not a valid batch file.

t-tests were run by importing the predictions into STATA, and using the 'ttest' command


guns = read.table(guns_1915_2004.csv, header = TRUE, sep = ,)
nobs = length(guns$fsuic)

# Repeat the following for each type of death rate (fsuic/fhom/nfsuic/nfhom)

  # levels

a1 <- arima(x = (guns$fsuic/guns$population*100000), order = c(1,1,1), xreg = 1: nobs)

p1 <- predict(a1, n.ahead = 10, newxreg = (nobs+1): (nobs+10))

# display results

a1

p1$pred

p1$se

   # logs

a2 <- arima(x = log(guns$fsuic/guns$population*100000), order = c(1,1,1), xreg = 1: nobs)

p2 <- predict(a2, n.ahead = 10, newxreg = (nobs+1): (nobs+10))

# display results

a2

p2$pred

p2$se